package com.garry.user.repository;

import com.garry.user.entity.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<User, Long>,
        JpaSpecificationExecutor<User> {
    @Modifying
    @Query("update User a set a.username = ?2 where a.id = ?1")
    int updateNameById(long id, String name);

    @Query(value = "select * from t_user where username=?1",nativeQuery = true)
    User findByUsername(String username);

}
